package analyzer

import (
	"fmt"
	"cloud_worm/util/umodels/mysqldb/dbdata"
	"cloud_worm/util/third/unotify"
)

type WeaponErrorInfo struct {
	Name        string				// wp name

	WormId      string
	Ip          string
	WeaponId    int64
	TaskId      string
}

func (w *WeaponErrorInfo) Deal() {
	// 得到源数据
	wpLog := &dbdata.WeaponLog{
		WormId: w.WormId,
		WeaponId: w.WeaponId,
		TaskId: w.TaskId,
	}
	err := wpLog.Read("worm_id", "weapon_id", "task_id")
	if err != nil {
		// todo: weapon log不存在
		return
	}

	if len(wpLog.ErrorInfo) == 0 {
		return
	}

	// 执行失败，提示ErrorInfo信息
	content := fmt.Sprintf("'%s' exec'%s' error: %s", w.Ip, w.Name, wpLog.ErrorInfo)
	ttItem := &unotify.IMNotifyItem{
		Grade:       unotify.ErrorGrade,
		Title:       unotify.DefaultTitle,
		Msg:         content,
		IMUsers: []string{
			"用学",
		},
	}
	unotify.IMNotifyInst.SendAsync(ttItem)

	return
}